<template>
	<uv-popup ref="popupRef" :mode="mode" :round="round" @maskClick="maskClick" @change="change">
		<view class="header">
			<view class="back-icon">
				<uv-icon name="arrow-left" color="#999999" size="22" @click="close"></uv-icon>
			</view>
			<view class="title">{{ title }}</view>
		</view>
		<view class="main">
			<slot></slot>
		</view>
		<view class="modal_btn" @click="submit" v-if="isShowBtn">确定</view>
	</uv-popup>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	defineProps({
		title: String,
		mode: {
			type: String,
			default: "center"
		},
		round: {
			type: Number,
			default: 20
		},
		isShowBtn: {
			type: Boolean,
			default: false
		}
	})
	const popupRef = ref()
	const emit = defineEmits(['submit', 'change', 'maskClick'])
	const open = () => {
		popupRef.value.open()
	}

	const close = () => {
		popupRef.value.close()
	}
	//点击遮罩触发
	const maskClick = () => {
		emit('maskClick')
	}
	const change = (e) => {
		if (e.show) {
			popupRef.value.open()
		} else {
			emit('change')
		}
	}

	const submit = () => {
		emit('submit')
	}

	defineExpose({
		open,
		close
	})
</script>

<style scoped lang="scss">
	.header {
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		margin-bottom: 20rpx;

		.back-icon {
			position: absolute;
			left: 18rpx;
			top: 52rpx;
		}

		.title {
			color: #222222;
			font-size: 32rpx;
			font-weight: 700;
			margin-top: 52rpx;
		}
	}

	.main {
		padding: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.modal_btn {
		width: 640rpx;
		height: 96rpx;
		background: #6E68E9;
		border-radius: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		color: #FFFFFF;
		font-weight: 500;
		margin: 20rpx auto 40rpx;
	}
</style>